-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add settings to rustdoc to use the system theme #77809
Conversation
Some changes occurred in HTML/CSS/JS. |
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @jyn514 (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit, but I think guillaume is the better reviewer for this. This looks really cool, thanks for working on it!
I'm not sure I understand how the current implementation of the theme system works. It says here that it works by changing the href of the I'd like to know so I can properly implement a fix to support JavaScript disabled browsers to use the system theme :) |
@Cldfire might know ^ |
The |
I tried getting rid of the Usage of the |
What is the forward/backwards compatibility of this? All docs hosted on docs.rs are using a shared |
I didn't change the way It actually even improves backwards: when the system theme is set, it's saved to |
(This also looks relatively easy for docs.rs to hijack to configure its own theme (when we get support), other than the lack of self- |
Actually I think I should make sure it works properly with JavaScript disabled before merging. Currently it doesn't work, because the logic is in @import "{static_root_path}light{suffix}.css" (prefers-color-scheme: light);
@import "{static_root_path}dark{suffix}.css" (prefers-color-scheme: dark); The problem with this is that the styles might override each other in bad ways (since there's already the javascript controlled |
By default it's the light theme that gets displayed, so if you get the same result, it's working the same as currently! But if you want to extend it (which would be nice!), please do so but in another PR so we can get this one merged. |
Actually the old behavior was using the system theme by default! You can try it by opening the standard library documentation in a private window (so that |
Hmmmm... Makes sense in a way I guess? |
Yeah, because the old method used So should I add support for JavaScript disabled browsers in another PR or this one to keep backwards compatibility with the old behavior? |
Isn't that the intended behavior? What more is there to change? |
Also, if |
I can implement that logic! I suppose that for now I should hard-code what theme is "dark" and what theme is "light"? |
This can cause issues:
One potential fix would be to not save the theme to |
Seems a bit of an edge case ... but since it leads to rustdoc overriding the user's selection, better to avoid it. Rather than having complicated logic, let's just only implement my first suggestion: If use-system-theme and preferred-dark-theme aren't set, but rustdoc-theme is set to a dark theme, update preferred-dark-theme to that theme. |
Is it an edge case? My phone does this too. |
You can write the canonical list :) There's only three themes, it seems reasonable to have a |
If the user doesn't have a preferred dark theme but is already using a dark theme, set the preferred dark theme to be that theme
That should be implemented now! I think it's ready now. |
Looks great! Thanks so much for working on this :) @bors r=jyn514,guillaumegomez |
📌 Commit 59f9cf2 has been approved by |
I wonder if we can have a css fallback rather than relying on javascript? Some users may have disabled javascript. |
I thought about this already and I think I may implement a CSS fallback in a future PR. I already have a few ideas about how it could work but I'd prefer to discuss about it first :) |
☀️ Test successful - checks-actions, checks-azure |
This PR adds new settings to
rustdoc
to use the operating system color scheme.rustdoc
actually had basic support for this, but the setting wasn't visible and couldn't be set back once the theme was explicitly set by the user. It also didn't update if the operating system theme preference changed while viewing a page.I'm using this method to query and listen to changes to the
(prefers-color-scheme: dark)
media query. I kept the old method (based ongetComputedStyle
) as a fallback in case the user-agent doesn't supportwindow.matchMedia
(so like... pretty much nobody).Since there's now more than one official ""dark"" theme in
rustdoc
(and also to support custom/third-party themes), the preferred dark and light themes can be configured in the settings page (the defaults are just "dark" and "light").This is also my very first "proper" PR to Rust! Please let me know if I did anything wrong :).